﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;

namespace CDDocumentExtractor
{
    public partial class frmOptions : Form
    {
        public frmOptions()
        {
            InitializeComponent();
        }

        private void cmdApply_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(txtExtractedDocuments.Text.Trim()))
                Directory.CreateDirectory(txtExtractedDocuments.Text.Trim());

           WebUtility.Write("sourceDocuments", txtExtractedDocuments.Text.Trim());

            //Write("documentCount", documentCount);

            if (!File.Exists(txtErrorFile.Text.Trim()))
                File.CreateText(txtErrorFile.Text.Trim());
            WebUtility.Write("errorFile", txtErrorFile.Text.Trim());
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmOptions_Load(object sender, EventArgs e)
        {
            txtExtractedDocuments.Text = WebUtility.Read("sourceDocuments");
            txtErrorFile.Text = WebUtility.Read("errorFile");
            txtDocumentCount.Text = WebUtility.Read("documentCount");

            if (string.IsNullOrEmpty(txtExtractedDocuments.Text))
            {
                WebUtility.Write("sourceDocuments", "c:\\InfoOneSourceDocuments");
                txtExtractedDocuments.Text = WebUtility.Read("sourceDocuments");
            }

            //Create directory if not exists
            if (!Directory.Exists(txtExtractedDocuments.Text))
                Directory.CreateDirectory(txtExtractedDocuments.Text);

            if (string.IsNullOrEmpty(txtDocumentCount.Text))
            {
                WebUtility.Write("documentCount", "0");
                txtDocumentCount.Text = "0";
            }

            if (string.IsNullOrEmpty(txtErrorFile.Text))
            {
                WebUtility.Write("errorFile", "c:\\InfoOneSourceDocuments\\Error\\ErrorDocument.txt");
                txtErrorFile.Text = WebUtility.Read("errorFile");
            }
        
        }
    }
}
